//
//  ListenToBookController.m
//  LazyEnglish
//
//  Created by lanou3g on 16/1/5.
//  Copyright © 2016年 李洋. All rights reserved.
//

#import "ListenToBookController.h"
#import "ImageCell.h"
#import "ListViewController.h"


@interface ListenToBookController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@end

@implementation ListenToBookController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //创建layout对象
    UICollectionViewFlowLayout *layout =[[UICollectionViewFlowLayout alloc] init];
    //配置属性
    
    layout.minimumLineSpacing =50;
    
    layout.minimumInteritemSpacing =30;
    
    layout.itemSize =CGSizeMake(70, 70);
    
    layout.sectionInset =UIEdgeInsetsMake(20, 20, 20, 20);
    //创建collectionView
    UICollectionView *collectionView =[[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:layout];
    collectionView.backgroundColor =[UIColor cyanColor];
    
    //添加到父视图
    [self.view addSubview:collectionView];
    
    
    //设置代理
    collectionView.delegate =self;
    collectionView.dataSource =self;
    //注册标记
    [collectionView registerClass:[ImageCell class] forCellWithReuseIdentifier:@"imageCell"];
    
    
    
    
    
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 15;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ImageCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:@"imageCell" forIndexPath:indexPath];
    
    cell.imageView.image =[UIImage imageNamed:@"1.jpg"];
    cell.nameLable.text =@"wokao";
    return cell;
    
    
}

#pragma mark  --实现代理的方法
-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

//点击item执行的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ListViewController *listVC =[[ListViewController alloc] init];
    UINavigationController *nav2 =[[UINavigationController alloc] initWithRootViewController:listVC];
    
    [self presentViewController:nav2 animated:YES completion:nil];
    
}

@end
